package com.kaili.basic.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.mapper.BaseCarrierMapper;
import com.kaili.basic.pojo.dto.BaseCarrierAddDto;
import com.kaili.basic.pojo.entity.BaseCarrier;
import com.kaili.basic.service.BaseCarrierService;
import com.kaili.common.util.LoginDetailUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BaseCarrierServiceImpl implements BaseCarrierService {

    @Autowired
    private BaseCarrierMapper carrierMapper;

    @Override
    public void addCarrier(BaseCarrierAddDto carrierAddDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseCarrier baseCarrier = new BaseCarrier();
        BeanUtils.copyProperties(carrierAddDto, baseCarrier);
        if (uid != null) {
            baseCarrier.setCreateBy(uid.longValue());
            baseCarrier.setCreateTime(new Date());
            carrierMapper.addCarrier(baseCarrier);
        }
    }

    @Override
    public void deleteCarrier(Long carrierId) {
        carrierMapper.deleteCarrier(carrierId);
    }

    @Override
    public void updateCarrier(BaseCarrierAddDto carrierAddDto) {
        Integer uid = LoginDetailUtils.getCurrentEmployeeId();
        BaseCarrier baseCarrier = new BaseCarrier();
        BeanUtils.copyProperties(carrierAddDto, baseCarrier);
        if (uid != null) {
            baseCarrier.setModifyBy(uid.longValue());
            baseCarrier.setModifyTime(new Date());
            carrierMapper.updateCarrier(baseCarrier);
        }
    }

    @Override
    public Page<BaseCarrier> queryCarrier(Page<BaseCarrier> page, BaseCarrier carrier) {
        List<BaseCarrier> list = carrierMapper.queryCarrier(page ,carrier);
        return page.setRecords(list);
    }

    @Override
    public List<BaseCarrier> queryCarrierByLike(BaseCarrier carrier) {
        return carrierMapper.queryCarrier(carrier);
    }

    @Override
    public String getCarrierCode() {
        return carrierMapper.getCarrierCode();
    }
}
